package com.minispider.entity;

import com.minispider.util.HtmlDocument;
import com.minispider.util.Logger;

public class MopEntity extends ParamEntity {

	public void getNextPageHref(HtmlDocument hd) throws Exception {
		this.url = null;
	}
	
	public boolean hasMorePage() {
		return false;
	}
	
	public void process() throws Throwable {
		
	    if (this.data.size() == 0) return;
	    
	    int size = this.data.get(0).length;

	    for (int i = 0; i < size; i++) {
	    	
	    	Logger.info(this.data.get(0)[i].toString() + "###" + this.data.get(1)[i].toString()
	    			+ "###" + this.data.get(2)[i].toString());
    			    	
	    	String s = this.data.get(2)[i].toString().trim();
	    	
    		String title = s.substring(0, s.lastIndexOf("("));
	    	
    		int rtime =Integer.valueOf(s.substring(s.lastIndexOf("(") + 1, s.lastIndexOf("条")));
    		
    		rtime = rtime > 0 ? rtime : 0;
    		
    		int r = this.db.executeUpdate("UPDATE article_info set rtime =" + rtime 
		 							+ " where wid=" + this.ids.get(0) 
		 							+ " and cid=" + this.ids.get(1) 
		 							+ " and aid=" + this.data.get(0)[i].toString() + ";");

    		if (r == 0) {
    			 this.db.executeUpdate(
    					 "insert into article_info(wid,cid,aid,title,url,rtime,cdate)values("
    					 + this.ids.get(0) + "," + this.ids.get(1) + "," + this.data.get(0)[i].toString() + ",'" 
    					 + title + "','" 
    					 + this.data.get(1)[i].toString() + "'," 
    					 + rtime + "," 
    					 + "now());");
    		}
    		
	    }
	    
	}
	
}
